package com.aspira.controller;

import com.aspira.entity.User;
import com.aspira.service.userservice.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService service;

    @RequestMapping("/save")
    public User save(UserVo userVo) throws ParseException {
        User user = new User();
//        user.setAge(userVo.getAge());
//        String birthday = userVo.getBirthday();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

//        user.setCityId(userVo.getCityId());
//        user.setUserId(userVo.getUserId());
//        user.setUserName(userVo.getUserName());

        BeanUtils.copyProperties(userVo, user, "birthday" );
        user.setBirthday(simpleDateFormat.parse(userVo.getBirthday()));
        return service.save(user);
    }
}
